Repository navigation
fix(settings): normalize and validate branch prefixes - #7772
Conversation
📝 WalkthroughWalkthroughThis PR adds shared branch-prefix normalization and validation utilities, a new Sequence Diagram(s)Not applicable — the PR is split across utility, wiring, and UI changes rather than one single end-to-end flow. Related Issues: Not specified. Related PRs: Not specified. Suggested labels: enhancement, main-process, renderer, i18n, tests Suggested reviewers: Not specified. Poem 🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
🧹 Nitpick comments (2)
src/main/runtime/orca-runtime.ts (1)
1429-1429: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick winUse
BranchPrefixSettingshere and add a closed fallback.worktree-remote.tsalready usesBranchPrefixSettingsfor the same helper, so the local{ branchPrefix: string; branchPrefixCustom?: string }shape is what forces theas BranchPrefixStrategycast.selectBranchPrefixInputalso falls through on unexpected values, so adefault: return nullwould make the fallback explicit.src/renderer/src/components/settings/BranchPrefixFeedback.tsx (1)
9-9: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick winPrefer
ReactNodeoverJSX.Elementfor the return type.Static analysis flags this:
JSX.Elementexcludesnull/strings/numbers that components commonly return. The component doesn't hit that case today, but constraining the return type this way makes future changes (e.g., returningnulldirectly instead of always wrapping in<p>) a type error for no benefit.🛠️ Proposed fix
-import type { JSX, ReactNode } from 'react' +import type { ReactNode } from 'react' import { getBranchPrefixIssue, normalizeBranchPrefix } from '../../../../shared/branch-prefix' import { translate } from '`@/i18n/i18n`' type BranchPrefixFeedbackProps = { rawPrefix: string } -export function BranchPrefixFeedback({ rawPrefix }: BranchPrefixFeedbackProps): JSX.Element { +export function BranchPrefixFeedback({ rawPrefix }: BranchPrefixFeedbackProps): ReactNode {Source: Linters/SAST tools
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Pro
Run ID: 8b6ea411-e5cd-49a3-904b-c9d63d5a0f0b
📥 Commits
Reviewing files that changed from the base of the PR and between 2ce77d9 and e29bfba0e6603fc68e890b8f90c9f30dc373114e.
📒 Files selected for processing (18)
src/main/agent-hooks/first-work-branch-rename.tssrc/main/ipc/worktree-branch-name.tssrc/main/ipc/worktree-logic.test.tssrc/main/ipc/worktree-logic.tssrc/main/ipc/worktree-remote.tssrc/main/runtime/orca-runtime.tssrc/renderer/src/components/settings/BranchPrefixFeedback.test.tsxsrc/renderer/src/components/settings/BranchPrefixFeedback.tsxsrc/renderer/src/components/settings/GitPane.test.tsxsrc/renderer/src/components/settings/GitPane.tsxsrc/renderer/src/i18n/locales/en.jsonsrc/renderer/src/i18n/locales/es.jsonsrc/renderer/src/i18n/locales/ja.jsonsrc/renderer/src/i18n/locales/ko.jsonsrc/renderer/src/i18n/locales/zh.jsonsrc/shared/branch-prefix.test.tssrc/shared/branch-prefix.tssrc/shared/types.ts
|
Thanks @coderabbitai — addressed the nitpicks:
|
|
Tip For best results, initiate chat on the files or code changes. The PR description image (Screenshot 2026-07-07 at 10 26 45 PM) shows a "Branch Prefix" settings panel with options "Git Username", "Custom" (selected), and "None". A text input contains "core-team", with helper text below reading "Branches will be named core-team/feature". The PR description image (Screenshot 2026-07-07 at 10 28 27 PM) shows the same panel with "Custom" selected and the input containing "core team" (with a space). Below the input, red validation text reads "Prefix cannot contain spaces or special characters like ~ ^ : ? * [ ".
On the other two points, both explanations make sense to me:
Thanks for walking through the reasoning on both — nothing further needed from me on these two. (◕‿◕) |
c801840 to
c5d2030
Compare
A custom branch prefix ending in a slash (e.g. "team/") produced a double-slashed branch name like "team//feature" that git rejects, and the raw check-ref-format error gave no hint that the prefix caused it. - Normalize the configured prefix (trim whitespace, strip leading/ trailing and duplicate slashes) in the shared branch-name builder so the common trailing-slash case just works, for local and SSH worktrees. - Validate the prefix on the worktree-create path (computeValidatedBranchName) so a genuinely invalid prefix fails fast with a clear "update it in Settings -> Git" message instead of an opaque git error. - Add a live BranchPrefixFeedback under the Branch Prefix setting: previews the resulting branch name, warns on invalid characters, and notes when a prefix collapses to none. - Keep the background first-work rename on the non-throwing builder since the prefix is already validated at create time.
The custom branch prefix input was directly controlled by settings, but updateSettings persists through an async IPC round-trip, so the value updated a tick late and React re-assigned it, snapping the caret to the end on mid-string edits. Drive the input from a local draft and only adopt genuine external settings changes so the caret stays put (and fast typing survives slow SSH round-trips). Co-authored-by: Cursor <cursoragent@cursor.com>
JSX.Element needlessly excludes null/string/number returns; ReactNode keeps the component's return type from over-constraining future changes. Co-authored-by: Cursor <cursoragent@cursor.com>
c5d2030 to
ba10d01
Compare
|
Thanks so much @yoelfme — the branch-prefix normalize/validate fix (no more |
* Normalize branch prefixes and flag invalid ones in settings A custom branch prefix ending in a slash (e.g. "team/") produced a double-slashed branch name like "team//feature" that git rejects, and the raw check-ref-format error gave no hint that the prefix caused it. - Normalize the configured prefix (trim whitespace, strip leading/ trailing and duplicate slashes) in the shared branch-name builder so the common trailing-slash case just works, for local and SSH worktrees. - Validate the prefix on the worktree-create path (computeValidatedBranchName) so a genuinely invalid prefix fails fast with a clear "update it in Settings -> Git" message instead of an opaque git error. - Add a live BranchPrefixFeedback under the Branch Prefix setting: previews the resulting branch name, warns on invalid characters, and notes when a prefix collapses to none. - Keep the background first-work rename on the non-throwing builder since the prefix is already validated at create time. * Keep caret in place when editing the branch prefix The custom branch prefix input was directly controlled by settings, but updateSettings persists through an async IPC round-trip, so the value updated a tick late and React re-assigned it, snapping the caret to the end on mid-string edits. Drive the input from a local draft and only adopt genuine external settings changes so the caret stays put (and fast typing survives slow SSH round-trips). Co-authored-by: Cursor <cursoragent@cursor.com> * Return ReactNode from BranchPrefixFeedback JSX.Element needlessly excludes null/string/number returns; ReactNode keeps the component's return type from over-constraining future changes. Co-authored-by: Cursor <cursoragent@cursor.com> --------- Co-authored-by: Cursor <cursoragent@cursor.com>
Summary
Fixes worktree creation failing with a cryptic
fatal: 'team//main' is not a valid branch namegit error when a custom branch prefix ends in a slash (e.g.team/).ELI5
If you typed your branch prefix with a slash at the end — the natural way to write it — the app broke with a confusing error. Now it cleans up the prefix automatically and warns you right in Settings if it's still invalid.
Root cause & fix
The branch-name builder joins
${prefix}/${leaf}, so a trailing-slash prefix liketeam/produced a double slash (team//main), and that computed name — unlike an explicit branch override — never passed throughgit check-ref-format, so it failed raw atgit worktree add. A new shared helper (src/shared/branch-prefix.ts) normalizes prefixes (trim, strip leading/trailing and duplicate slashes) and validates them; worktree-create paths now usecomputeValidatedBranchNameto fail fast with a clear "update it in Settings → Git" message. Live renderer feedback previews the resulting branch name and flags invalid characters. Best-effort background auto-rename intentionally keeps the non-throwing builder since the prefix is already validated at create time.Evidence
Validated & rebased onto latest main during a bug-bash triage on 2026-07-23. Clean rebase onto
origin/main(base7ab601487c, headc8018405fd).branch-prefix.tsandBranchPrefixFeedback.tsx) while keeping the new tests yields 11 failed / 69 passed — the tests genuinely capture the bug.jdoe/feature(trailing-slash username normalization),Prefix cannot contain spaces(invalid-char warning), andNo prefix will be applied(empty-after-normalize).oxlint 1.71.0exit 0, no warnings/errors on changed source.Trade-offs
None — pure fix.
Regression risk
Zero-regression by construction: for valid prefixes
computeValidatedBranchNamereturns the same value as the oldcomputeBranchName; normalization only alters prefixes that were already broken (team/→team//name). Only genuinely-invalid prefixes now throw a clear settings error instead of failing later atgit check-ref-format(net improvement). Auto-rename retains its non-throwing path. Local and SSH worktree paths are both covered by the shared main-process builder. Proven by the passing test suite.Original fix by @yoelfme. Validated, rebased, and reviewed via automated bug-bash triage on 2026-07-23; original fix design preserved.